var index = parent.layer.getFrameIndex(window.name); //当前窗口索引
layui.use(['form','jquery','layer'],function(){
    var form = layui.form,
        $    = layui.jquery,
        layer = layui.layer;

    form.on("submit(editUser)",function(data){
        if(data.field.userid == null){
            layer.msg("用户ID不存在");
            return false;
        }
        if (data.field.state){
            data.field.state =1;
        }else {
            data.field.state = 0;
        }
        var loadIndex = layer.load(2, {
            shade: [0.3, '#333']
        });
        $.ajax({
            type:"POST",
            url:"/user/edit",
            dataType:"json",
            contentType:"application/json",
            data:JSON.stringify(data.field),
            success:function(res){
                layer.close(loadIndex);
                if(res.meta.code ==200){
                    parent.layer.msg("用户编辑成功！",{time:1500},function(){
                        parent.location.reload();
                    });
                }else{
                    layer.msg(res.data);
                }
            }
        });
        return false;
    });

   /* form.on('switch(adminUser)', function(data){
        $("#adminUser").val(data.elem.checked);
    });*/

    form.on('switch(state)', function(data){
        $("#state").val(data.elem.checked);
    });

});